﻿using System;
using System.Net;

namespace network{
    public class IpToInformation{
        public static void GetInformation(){
            string IpString;
            Console.Write("请输入一个IP地址：");
            IpString = Console.ReadLine();
            try {
                IPAddress myIp = IPAddress.Parse(IpString);
                IPHostEntry myHost = new IPHostEntry();
                myHost = Dns.GetHostEntry(myIp);
                var hostName = myHost.HostName;
                Console.WriteLine("主机名是：{0}", hostName);
                Console.WriteLine("相关的IP地址是：");
                
                foreach (var address in myHost.AddressList) {
                    Console.WriteLine(address);
                }
                
                if (myHost.Aliases.Length > 0) {
                    Console.WriteLine("主机别名是：");
                    foreach(var alias in myHost.Aliases){
                        Console.WriteLine(alias);
                    }
                }
                else {
                    Console.WriteLine("本机没有别名！");
                }
            }
            catch (Exception e) {
                Console.WriteLine(e.Message);
            }
        }
    }
}